// ignore_for_file: unused_element

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:gourmet/color/hex.dart';
import 'package:gourmet/extensions/ex_widget.dart';
import 'package:gourmet/route/index.dart';
import 'package:gourmet/utils/colors.dart';
import 'package:gourmet/utils/styles.dart';

class FeedbackMineController extends GetxController {
  final double navHeight = 44 + Get.mediaQuery.padding.top;
  final double navTop = 44.0;
}

class FeedbackMinePage extends GetView<FeedbackMineController> {
  const FeedbackMinePage({super.key});

  @override
  Widget build(BuildContext context) {
    return MediaQuery.removeViewPadding(
      context: context,
      removeTop: true,
      removeLeft: true,
      removeRight: true,
      removeBottom: true,
      child: Scaffold(
        backgroundColor: HexColor(ColorsUtils.colorF7f7),
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(controller.navHeight),
          child: AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.dark,
            child: Container(
              color: HexColor(ColorsUtils.colorF7f7),
              height: controller.navHeight,
              padding: Get.mediaQuery.padding,
              child: Stack(
                children: [
                  Positioned(
                    width: 40,
                    height: controller.navTop,
                    top: 0,
                    left: 0,
                    child: Center(
                      child: Icon(
                        CupertinoIcons.chevron_back,
                        size: 20,
                        color: HexColor(ColorsUtils.color0000),
                      ),
                    ).onTap(Get.back),
                  ),
                  Center(
                    child: Text(
                      '我的反馈',
                      softWrap: true,
                      style: StylesUtils.customTextStyle(
                        fontSize: StylesUtils.fontSize16,
                        fontWeight: FontWeight.w700,
                        color: ColorsUtils.color0000,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        body: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                margin: insets,
                padding: const EdgeInsets.all(15),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  color: Colors.white,
                ),
                child: ListBody(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '反馈内容',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize15,
                            color: ColorsUtils.color0000,
                          ),
                        ),
                        Text(
                          '2098-04-30 11:50',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize12,
                            color: ColorsUtils.color9999,
                          ),
                        ),
                      ],
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '【功能体验】这是一条功能建议，这是一条功能建议，这是一条功能建议，这是一条功能建议，这是一条功能建议，如下图所示。希望能及时改正。',
                        style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color0000,
                          lineHeight: 1.5,
                        ),
                      ),
                    ),
                    Wrap(
                      spacing: 15,
                      runSpacing: 15,
                      crossAxisAlignment: WrapCrossAlignment.center,
                      children: [
                        ClipRRect(
                          borderRadius: BorderRadius.circular(5),
                          child: Image.network(
                            'https://img1.baidu.com/it/u=737202614,1671027193&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333',
                            width: 80,
                            height: 80,
                            fit: BoxFit.fill,
                          ),
                        )
                      ],
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      alignment: Alignment.center,
                      child: Container(
                        width: 315,
                        padding: const EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(5),
                          color: ColorsUtils.rgba(249, 249, 249, 1),
                        ),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '客服回复',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                                Text(
                                  '2098-04-30 14:57',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              padding: const EdgeInsets.symmetric(vertical: 10),
                              alignment: Alignment.centerLeft,
                              child: Text(
                                '您好，感谢您的支持。请提供清晰截图，以便我们能快速定位问题！',
                                style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize13,
                                  color: ColorsUtils.color7979,
                                  lineHeight: 1.5,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Center(
                      child: CustomPaint(
                        painter: _GradientBoundPainter(colors: [
                          HexColor(ColorsUtils.colorFf99),
                          HexColor(ColorsUtils.colorFe46)
                        ]),
                        child: Container(
                          width: 235,
                          height: 40,
                          alignment: Alignment.center,
                          child: Text(
                            '反馈补充',
                            style: StylesUtils.customTextStyle(
                              color: ColorsUtils.colorFf64,
                              fontSize: StylesUtils.fontSize15,
                            ),
                          ),
                        ).onTap(() {
                          Get.toNamed(Routes.feedbackReplenishment);
                        }),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                margin: insets,
                padding: const EdgeInsets.all(15),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  color: Colors.white,
                ),
                child: ListBody(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '补充内容',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize15,
                            color: ColorsUtils.color0000,
                          ),
                        ),
                        Text(
                          '2098-04-30 12:50',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize12,
                            color: ColorsUtils.color9999,
                          ),
                        ),
                      ],
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '抱歉，图来了！',
                        style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color0000,
                          lineHeight: 1.5,
                        ),
                      ),
                    ),
                    Wrap(
                      spacing: 15,
                      runSpacing: 15,
                      crossAxisAlignment: WrapCrossAlignment.center,
                      children: [
                        ClipRRect(
                          borderRadius: BorderRadius.circular(5),
                          child: Image.network(
                            'https://img1.baidu.com/it/u=737202614,1671027193&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333',
                            width: 80,
                            height: 80,
                            fit: BoxFit.fill,
                          ),
                        )
                      ],
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      alignment: Alignment.center,
                      child: Container(
                        width: 315,
                        padding: const EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(5),
                          color: ColorsUtils.rgba(249, 249, 249, 1),
                        ),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '客服回复',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                                Text(
                                  '2098-04-30 14:57',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              padding: const EdgeInsets.symmetric(vertical: 10),
                              alignment: Alignment.centerLeft,
                              child: Text(
                                '您好，感谢您的支持。我会将该意见及时反馈给研发部门，加强改善。小默外卖的发展离不开您的支持，祝您生活愉快！',
                                style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize13,
                                  color: ColorsUtils.color7979,
                                  lineHeight: 1.5,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                margin: insets,
                padding: const EdgeInsets.all(15),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  color: Colors.white,
                ),
                child: ListBody(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '反馈内容',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize15,
                            color: ColorsUtils.color0000,
                          ),
                        ),
                        Text(
                          '2098-04-30 12:50',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize12,
                            color: ColorsUtils.color9999,
                          ),
                        ),
                      ],
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '【功能体验】这是一条功能建议，这是一条功能建议，这是一条功能建议，这是一条功能建议，这是一条功能建议，如下图所示。希望能及时改正。',
                        style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color0000,
                          lineHeight: 1.5,
                        ),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      alignment: Alignment.center,
                      child: Container(
                        width: 315,
                        padding: const EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(5),
                          color: ColorsUtils.rgba(249, 249, 249, 1),
                        ),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '客服回复',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                                Text(
                                  '2098-04-30 14:57',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              padding: const EdgeInsets.symmetric(vertical: 10),
                              alignment: Alignment.centerLeft,
                              child: Text(
                                '您好，感谢您的支持。请提供问题截图，以便我们能快速定位问题！',
                                style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize13,
                                  color: ColorsUtils.color7979,
                                  lineHeight: 1.5,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  EdgeInsets get insets {
    return EdgeInsets.only(
        left: (Get.width - 345) / 2, right: (Get.width - 345) / 2, top: 10);
  }
}

///
/// 边框渐变
///
class _GradientBoundPainter extends CustomPainter {
  final List<Color> colors;
  final double strokeWidth;
  final double radius;
  const _GradientBoundPainter({
    required this.colors,
    this.radius = 20,
    this.strokeWidth = 1.0,
  });

  @override
  void paint(Canvas canvas, Size size) {
    //定义矩形的宽高
    Rect rect = Offset.zero & size;
    //RRect.fromRectAndRadius一个具有圆角的矩形
    RRect rRect = RRect.fromRectAndRadius(rect, Radius.circular(radius));
    //绘制
    final paint = Paint()
      //创建线性渐变着色器
      ..shader = LinearGradient(
        begin: Alignment.centerLeft,
        end: Alignment.centerRight,
        colors: colors,
      ).createShader(rect)
      ..strokeWidth = strokeWidth
      //只绘制边框而不填充
      ..style = PaintingStyle.stroke;
    canvas.drawRRect(rRect, paint);
  }

  @override
  bool shouldRepaint(covariant _GradientBoundPainter oldDelegate) {
    return oldDelegate.colors != colors;
  }
}
